package com.axend.lib_base.help
import com.axend.lib_base.ext.roundToOne
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import kotlin.math.abs
import kotlin.math.round
import kotlin.random.Random

class TempMeasure {

    var maxDataWind = mutableListOf<List<Double>>()
    var maxDataLastData = 0.0
    var maxDataValid = mutableListOf<Double>()
    var maxDataZPercentCnt = 1
    var maxDataFPercentCnt = 1

    var vivoTempWind = mutableListOf<Double>()
    var vivoTempLastData = 0.0
    var vivoTempValid = mutableListOf<Double>()
    var vivoTempZPercentCnt = 1
    var vivoTempFPercentCnt = 1
    /**
     * """
     * :param dataValues_5sec:
     * :return:
     * 5秒内的数据，没0.6秒出一次数据，这一次数据是检测框内的温度数据，选择检测框内最大的前10个数据，
     * 去除最值后看方差大小，如果方差较大，则这0.6秒的数据无效，使用上一次的有效值
     * """
     * @return
     */
    // 类型是不是得改一改，mutableListOf？
    fun getArecValue(dataValues_5sec: List<List<Double>>): List<Double> {
        var lastTemp = 0.0
        val dataValues5secFinal = mutableListOf<Double>()

        for (i in dataValues_5sec.indices) {
            val dataValuesAsec = dataValues_5sec[i]

            // 排序并选择前10个最大值 sortedDescending().take(10)是Kotlin语言中的一个函数，主要用于对集合进行降序排序并取出前10个元素。
            val sortedArray = dataValuesAsec.sortedDescending().take(10)

            // 去除最大最小值后的方差计算  filter函数是一个实用的集合操作，它用于基于给定的条件从集合中选择元素
            val filteredArray = sortedArray.filter { it != sortedArray.maxOrNull() && it != sortedArray.minOrNull() }

            if (filteredArray.isNotEmpty()) {
                val variance = calculateVariance(filteredArray)

                if (variance < 0.1) {
                    // 方差较小，使用均值
                    val meanValue = filteredArray.average()
                    val roundedValue = round(meanValue * 10) / 10.0
                    dataValues5secFinal.add(roundedValue)
                    lastTemp = roundedValue
                } else {
                    // 方差较大，使用上一次的有效值
                    if (lastTemp > 0) {
                        dataValues5secFinal.add(lastTemp)
                    }
                }
            } else {
                // 如果过滤后的数组为空，直接使用上一次的有效值
                if (lastTemp > 0) {
                    dataValues5secFinal.add(lastTemp)
                }
            }
        }

        return dataValues5secFinal
    }

    // 计算方差的辅助函数
    fun calculateVariance(values: List<Double>): Double {
        val mean = values.average()
        return values.map { (it - mean) * (it - mean) }.average()
    }


    /**
     *"""
     *:param data_list: 滑动窗口内的数据
     *:param last_temp: 上一次的有效值
     *:param valid_list: 输出滑动窗口内的均值
     *:param Zpercent_cnt: 增值的占比比例
     *:param Fpercent_cnt：减值的占比比例
     *:return: last_dataSec，Zpercent_cnt，Fpercent_cnt,last_dataSec(输出值)
     *"""
     */
    // mutableListOf?
    fun calcAdata(
        data5secValue: List<Double>,
        lastDataSec: Double,
        validList: List<Double>,
        zPercentCnt: Int,
        fPercentCnt: Int
    ): Triple<Double, Int, Int> {
        var lastDataSec = lastDataSec  //上一个值
        var zPercentCnt = zPercentCnt
        var fPercentCnt = fPercentCnt

        if (data5secValue.size >= 4) { // 5s内至少有4条数据
            if (data5secValue.distinct().size == 1) { // 如果5秒内的所有数据相同
                var temp5sec = data5secValue[0]
                if (lastDataSec != 0.0) {
                    when {
                        abs(temp5sec - lastDataSec) < 0.3 -> {
                            lastDataSec = temp5sec
                            zPercentCnt = 1
                            fPercentCnt = 1
                        }
                        temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                            temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                            lastDataSec = temp5sec
                            zPercentCnt += 1
                            fPercentCnt = 1
                        }
                        temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                            temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                            lastDataSec = temp5sec
                            zPercentCnt = 1
                            fPercentCnt += 1
                        }
                    }
                } else {
                    lastDataSec = temp5sec
                }
                return Triple(lastDataSec, zPercentCnt, fPercentCnt)
            } else {
                //1.先统计数据分布区间
                //2.得到数据的区间
                val minValue = data5secValue.minOrNull() ?: 0.0
                val maxValue = data5secValue.maxOrNull() ?: 0.0
                val binWidth = (maxValue - minValue) / data5secValue.size

                val bins = generateSequence(minValue) { it + binWidth }.takeWhile { it <= maxValue }.toList()

                // Step 2: Calculate histogram counts (manually simulating np.histogram)
                val counts = IntArray(bins.size - 1) { 0 }
                for (value in data5secValue) {
                    for (i in 1 until bins.size) {
                        if (value >= bins[i - 1] && value < bins[i]) {
                            counts[i - 1]++
                            break
                        }
                    }
                }
                // Step 3: Find the index with the maximum count
                val maxIndex = counts.indexOf(counts.maxOrNull() ?: 0)
                // Step 4: Find indices with the same max count
                val indices = counts.withIndex().filter { it.value == counts[maxIndex] }.map { it.index }
                // Step 5: Find the bin with the closest value to the mean of validList
                val dataChoose = mutableListOf<Double>()
                var filteredMatrix:List<Double>
                if (indices.size >= 2) {
                    for (i in indices) {
                        val midBinValue = (bins[i] + (bins[i + 1] - bins[i]) / 2)
                        dataChoose.add(midBinValue - validList.average())
                    }
                    val closestIndex = dataChoose.indices.minByOrNull { abs(dataChoose[it]) } ?: 0
                     filteredMatrix = data5secValue.filter {
                        it in bins[indices[closestIndex]]..bins[indices[closestIndex] + 1]
                    }
                } else {
                     filteredMatrix = data5secValue.filter {
                        it in bins[maxIndex]..bins[maxIndex + 1]
                    }
                }
                // 找到输出范围的值
                if (filteredMatrix.size >= 4) {
                    //筛选后的矩阵是同一个值
                    if (filteredMatrix.distinct().size == 1){
                        var temp5sec = filteredMatrix.average()
                        //直接四舍五入
                        temp5sec = round(temp5sec * 10) / 10.0
                        if (lastDataSec != 0.0) {
                            when {
                                abs(temp5sec - lastDataSec) < 0.3 -> {
                                    lastDataSec = temp5sec
                                    zPercentCnt = 1
                                    fPercentCnt = 1
                                }

                                temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                    temp5sec =
                                        temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                    lastDataSec = temp5sec
                                    zPercentCnt += 1
                                    fPercentCnt = 1
                                }

                                temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                    temp5sec =
                                        temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                    lastDataSec = temp5sec
                                    zPercentCnt = 1
                                    fPercentCnt += 1
                                }
                            }
                        } else {
                            lastDataSec = temp5sec
                        }
                        return Triple(lastDataSec, zPercentCnt, fPercentCnt)

                    }
                    else {//筛选后的矩阵不是同一个值
                        var filteredMatrixDelM = filteredMatrix.filter { it != filteredMatrix.maxOrNull() && it != filteredMatrix.minOrNull() }
                        //不是只有最大和最小的数组成的矩阵
                        if (filteredMatrixDelM.isNotEmpty()) {
                            var temp5sec = filteredMatrixDelM.average()
                            //直接四舍五入
                            temp5sec = round(temp5sec * 10) / 10.0
                            if (lastDataSec != 0.0) {
                                when {
                                    abs(temp5sec - lastDataSec) < 0.3 -> {
                                        lastDataSec = temp5sec
                                        zPercentCnt = 1
                                        fPercentCnt = 1
                                    }

                                    temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                        temp5sec =
                                            temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                        lastDataSec = temp5sec
                                        zPercentCnt += 1
                                        fPercentCnt = 1
                                    }

                                    temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                        temp5sec =
                                            temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                        lastDataSec = temp5sec
                                        zPercentCnt = 1
                                        fPercentCnt += 1
                                    }
                                }
                            } else {
                                lastDataSec = temp5sec
                            }
                            return Triple(lastDataSec, zPercentCnt, fPercentCnt)
                        }
                        //去除最大最小后的矩阵为空 类似于这种矩阵[max,max,min,min]（概率最大范围内的数据）
                        else {
                            //找到每个值的次数
                            ///////////////////////////////////////////////////////////////
                            // Step 1: 获取唯一值和出现次数
                            val uniqueValues = filteredMatrix.distinct()
                            val counts = uniqueValues.map { value -> filteredMatrix.count { it == value } }

                            // Step 2: 找到出现次数最多的值的索引
                            val maxCount = counts.maxOrNull() ?: 0
                            val indices =
                                counts.withIndex().filter { it.value == maxCount }.map { it.index }
                            var temp5sec: Double
                            // Step 3: 如果出现次数最多的值有多个
                            if (indices.size >= 2) {
                                // 找到所有值的平均值，四舍五入到 1 位小数
                                temp5sec = filteredMatrix.average()
                                temp5sec = round(temp5sec * 10) / 10.0

                            } else {
                                // 否则返回出现次数最多的值
                                temp5sec = uniqueValues[indices[0]]
                            }
                            ///////////////////////////////////////////////////////////////
                            if (lastDataSec != 0.0) {
                                when {
                                    abs(temp5sec - lastDataSec) < 0.3 -> {
                                        lastDataSec = temp5sec
                                        zPercentCnt = 1
                                        fPercentCnt = 1
                                    }

                                    temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                        temp5sec =
                                            temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                        lastDataSec = temp5sec
                                        zPercentCnt += 1
                                        fPercentCnt = 1
                                    }

                                    temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                        temp5sec =
                                            temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                        lastDataSec = temp5sec
                                        zPercentCnt = 1
                                        fPercentCnt += 1
                                    }
                                }
                            } else {
                                lastDataSec = temp5sec
                            }
                            return Triple(lastDataSec, zPercentCnt, fPercentCnt)
                        }
                    }
                }
                else if (filteredMatrix.size == 3){
                    var temp5sec = filteredMatrix.sortedDescending()[1]//取中位数
                    if (lastDataSec != 0.0) {
                        when {
                            abs(temp5sec - lastDataSec) < 0.3 -> {
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt = 1
                            }
                            temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt += 1
                                fPercentCnt = 1
                            }
                            temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt += 1
                            }
                        }
                    } else {
                        lastDataSec = temp5sec
                    }
                    return Triple(lastDataSec, zPercentCnt, fPercentCnt)
                }
                else if (filteredMatrix.size == 2){
                    var temp5sec = filteredMatrix.average()
                    //直接四舍五入
                    temp5sec = round(temp5sec * 10) / 10.0
                    if (lastDataSec != 0.0) {
                        when {
                            abs(temp5sec - lastDataSec) < 0.3 -> {
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt = 1
                            }
                            temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt += 1
                                fPercentCnt = 1
                            }
                            temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt += 1
                            }
                        }
                    } else {
                        lastDataSec = temp5sec
                    }
                    return Triple(lastDataSec, zPercentCnt, fPercentCnt)
                }
                else if (filteredMatrix.size == 1){
                    //最大范围内的值只有1个
                    var temp5sec = filteredMatrix[0]
                    //直接四舍五入
                    if (lastDataSec != 0.0) {
                        when {
                            abs(temp5sec - lastDataSec) < 0.3 -> {
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt = 1
                            }
                            temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt += 1
                                fPercentCnt = 1
                            }
                            temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                                temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                                lastDataSec = temp5sec
                                zPercentCnt = 1
                                fPercentCnt += 1
                            }
                        }
                    } else {
                        lastDataSec = temp5sec
                    }
                    return Triple(lastDataSec, zPercentCnt, fPercentCnt)
                }
            }
        }
        else if (data5secValue.size == 3){
            var temp5sec = data5secValue.sortedDescending()[1]//取中位数
            if (lastDataSec != 0.0) {
                when {
                    abs(temp5sec - lastDataSec) < 0.3 -> {
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt = 1
                    }
                    temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt += 1
                        fPercentCnt = 1
                    }
                    temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt += 1
                    }
                }
            } else {
                lastDataSec = temp5sec
            }
            return Triple(lastDataSec, zPercentCnt, fPercentCnt)
        }else if (data5secValue.size == 2){
            var temp5sec = data5secValue.average()
            //直接四舍五入
            temp5sec = round(temp5sec * 10) / 10.0
            if (lastDataSec != 0.0) {
                when {
                    abs(temp5sec - lastDataSec) < 0.3 -> {
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt = 1
                    }
                    temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt += 1
                        fPercentCnt = 1
                    }
                    temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt += 1
                    }
                }
            } else {
                lastDataSec = temp5sec
            }
            return Triple(lastDataSec, zPercentCnt, fPercentCnt)
        }
        else if (data5secValue.size == 1){
            var temp5sec = data5secValue[0]
            //直接四舍五入
            if (lastDataSec != 0.0) {
                when {
                    abs(temp5sec - lastDataSec) < 0.3 -> {
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt = 1
                    }
                    temp5sec > lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * zPercentCnt + (1 - 0.1 * zPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt += 1
                        fPercentCnt = 1
                    }
                    temp5sec < lastDataSec && abs(temp5sec - lastDataSec) >= 0.3 -> {
                        temp5sec = temp5sec * 0.1 * fPercentCnt + (1 - 0.1 * fPercentCnt) * lastDataSec
                        lastDataSec = temp5sec
                        zPercentCnt = 1
                        fPercentCnt += 1
                    }
                }
            } else {
                lastDataSec = temp5sec
            }
            return Triple(lastDataSec, zPercentCnt, fPercentCnt)
        }
        // 当数据数量不符合要求时的处理
        return Triple(lastDataSec, zPercentCnt, fPercentCnt)
    }

    fun weightedRandomChoice(values: List<Double>, weights: List<Double>, k: Int = 1): Double {
       // 计算权重的总和
        val totalWeight = weights.sum()
       // 根据权重随机选择
        val chosenItems = mutableListOf<Double>()
        repeat(k) {
            val randomValue = Random.nextDouble(totalWeight) // 获取一个随机数，范围从 0 到 totalWeight
            var cumulativeWeight = 0.0
            // 找到对应的元素
            for (i in values.indices) {
                cumulativeWeight += weights[i]
                if (randomValue < cumulativeWeight) {
                    chosenItems.add(values[i])
                    break
                }
            }
        }
        return chosenItems[0]
    }
    // 时间处理：获取加减 5 毫秒后的时间
    fun timeMsecondList(timeStr: String, i: Int): MutableList<String> {
        val finalTimeList = mutableListOf<String>()
        val dateFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss_SSS", Locale.US)
        val dt = dateFormat.parse(timeStr) ?: return finalTimeList
        val calendar = Calendar.getInstance()
        calendar.time = dt

        // 增加5毫秒
        calendar.add(Calendar.MILLISECOND, i)
        val dtPlus5ms = dateFormat.format(calendar.time)

        // 减去5毫秒
        calendar.add(Calendar.MILLISECOND, -2 * i)
        val dtMinus5ms = dateFormat.format(calendar.time)

        finalTimeList.add(dtPlus5ms)
        finalTimeList.add(dtMinus5ms)
        return finalTimeList
    }

    // 数据融合方法
    fun fusion(
        maxDataWind: MutableList<List<Double>>, maxDataLastData: Double, maxDataValid: MutableList<Double>, maxDataZPercentCnt: Int, maxDataFPercentCnt: Int,
        vivoTempWind: MutableList<Double>, vivoTempLastData: Double, vivoTempValid: MutableList<Double>, vivoTempZPercentCnt: Int, vivoTempFPercentCnt: Int
    ): List<Any?> {
        var maxDataLastData = maxDataLastData
        var maxDataZPercentCnt = maxDataZPercentCnt
        var maxDataFPercentCnt = maxDataFPercentCnt
        var vivoTempLastData = vivoTempLastData
        var vivoTempZPercentCnt = vivoTempZPercentCnt
        var vivoTempFPercentCnt = vivoTempFPercentCnt
        var finalData: Any? = null

        if (maxDataWind.size == 8 && vivoTempWind.size == 8) {
            val maxDataWindData = getArecValue(maxDataWind)
            val result = calcAdata(maxDataWindData, maxDataLastData, maxDataValid, maxDataZPercentCnt, maxDataFPercentCnt)
            maxDataLastData = result.first
            maxDataZPercentCnt = result.second
            maxDataFPercentCnt = result.third
//            val maxDataFinal = result.fourth
            val maxDataFinal = maxDataLastData

            if (maxDataValid.size == 8) {
                maxDataValid.removeAt(0)
            }
            if (maxDataValid.size < 8) {
                maxDataValid.add(maxDataFinal)
            }

            val vivoTempResult = calcAdata(vivoTempWind, vivoTempLastData, vivoTempValid, vivoTempZPercentCnt, vivoTempFPercentCnt)
            vivoTempLastData = vivoTempResult.first
            vivoTempZPercentCnt = vivoTempResult.second
            vivoTempFPercentCnt = vivoTempResult.third
            val vivoTempFinal = vivoTempLastData
//            val vivoTempFinal = vivoTempResult.fourth

            if (vivoTempValid.size == 8) {
                vivoTempValid.removeAt(0)
            }
            if (vivoTempValid.size < 8) {
                vivoTempValid.add(vivoTempFinal)
            }

            maxDataWind.removeAt(0)
            vivoTempWind.removeAt(0)

            if (vivoTempWind.count { it == 35.8 } >= 4 || vivoTempWind.count { it == 42.0 } >= 4 || vivoTempWind.count { it == 35.9 } >= 6) {
                if (vivoTempWind.count { it == 35.8 } >= 4|| vivoTempWind.count { it == 35.9 } >= 6) {
                    //低温截断分情况补偿到36度及以上
                    if(30.0 <= maxDataFinal && maxDataFinal < 32.0){
                        val values = listOf(36.0, 36.1)
                        val weights = values.map { it * maxDataFinal }
                        val Max_data_Out = weightedRandomChoice(values, weights, k = 1)
                        finalData = Max_data_Out
                    }
                    else if ( 32.0 <= maxDataFinal &&  maxDataFinal<=  35.0) {
                        val values = listOf(36.2, 36.3, 36.4, 36.5)
                        val weights = values.map { it * maxDataFinal }

                        val Max_data_Out = weightedRandomChoice(values, weights, k = 1)
                        finalData = Max_data_Out
                    }
                    else{
                        finalData = maxDataFinal + 2.4
                    }
                }
                else{//这是高温截断
                    finalData = maxDataFinal + 2.4}
            } else {
                finalData = vivoTempFinal
            }
        }
        return listOf(maxDataWind, maxDataLastData, maxDataValid, maxDataZPercentCnt, maxDataFPercentCnt, vivoTempWind, vivoTempLastData, vivoTempValid, vivoTempZPercentCnt, vivoTempFPercentCnt, finalData)
    }

    // 从文件获取数据并融合处理
    fun finalOutWithFile(maxData: List<Double>, vivoTemp: Double):String {
        maxDataWind.add(maxData)
        vivoTempWind.add(vivoTemp)
        //fusionResult = listOf(maxDataWind, maxDataLastData, maxDataValid, maxDataZPercentCnt, maxDataFPercentCnt, vivoTempWind, vivoTempLastData, vivoTempValid, vivoTempZPercentCnt, vivoTempFPercentCnt, finalData)
        val fusionResult = fusion(maxDataWind, maxDataLastData, maxDataValid, maxDataZPercentCnt, maxDataFPercentCnt, vivoTempWind, vivoTempLastData, vivoTempValid, vivoTempZPercentCnt, vivoTempFPercentCnt)
        maxDataWind= fusionResult[0] as MutableList<List<Double>>
        maxDataLastData = fusionResult[1] as Double
        maxDataValid = fusionResult[2] as MutableList<Double>
        maxDataZPercentCnt = fusionResult[3] as Int
        maxDataFPercentCnt = fusionResult[4] as Int
        vivoTempWind = fusionResult[5] as MutableList<Double>
        vivoTempLastData = fusionResult[6] as Double
        vivoTempValid = fusionResult[7] as MutableList<Double>
        vivoTempZPercentCnt = fusionResult[8] as Int
        vivoTempFPercentCnt = fusionResult[9] as Int
    //        finalDataList.add(fusionResult[10]) // 获取最终的数据
        return if (fusionResult[10]!=null) ((fusionResult[10] as Double).roundToOne()).toString() else "null"
    }
}
